package com.itheima.thread.blockingqueue.demo02;

import java.util.concurrent.ArrayBlockingQueue;

public class ProducerThread implements Runnable {

    private ArrayBlockingQueue<Box> arrayBlockingQueue;
    public ProducerThread(ArrayBlockingQueue<Box> arrayBlockingQueue){
        this.arrayBlockingQueue = arrayBlockingQueue;
    }

    private int count = 0;
    @Override
    public void run() {
        while (true) {
            if (count % 2 == 0) {
                Box box = new Box();
                box.setMilkType("牛奶");
                box.setAmount("5L");
                try {
                    arrayBlockingQueue.put(box);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            } else {
                Box box = new Box();
                box.setMilkType("羊奶");
                box.setAmount("10L");
                try {
                    arrayBlockingQueue.put(box);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            count++;
        }
    }
}
